﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;

namespace RestaurantApp.Web.Infrastructure.Poco
{
    public class PersianServerDate
    {
        public int ShamsiYear { get; set; }
        public int ShamsiMonth { get; set; }
        public int ShamsiDay { get; set; }

        public Boolean IsIntercalaryYear { get; set; }

        public DateTime CurrentDate { get; set; }


        public PersianServerDate GetCurrentDate(string PersianDate)
        {
            PersianServerDate ret=new PersianServerDate();
            ret.CurrentDate=new DateTime();

            if ((string.IsNullOrEmpty(PersianDate)))
                ret.CurrentDate = DateTime.Now;
            else
            {
                string[] temp = PersianDate.Split('/');
                if (temp.Length == 3)
                {
                    ret.ShamsiYear = Convert.ToInt32(temp[0]);
                    ret.ShamsiMonth = Convert.ToInt32(temp[1]);
                    ret.ShamsiDay = Convert.ToInt32(temp[2]);
                    ret.CurrentDate = new System.Globalization.PersianCalendar().ToDateTime(ret.ShamsiYear,ret.ShamsiMonth,ret.ShamsiDay,0,0,0,0);
                }
                else
                    return null;
            }
            return ret;
        }

    }
}